﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using StoragePeriod.IDAL.StorageForecast;
using StoragePeriod.DALFactory;
using StoragePeriod.Model.StorageForecast;

namespace StoragePeriod.BLL.StorageForecast
{
    /// <summary>
    /// 品质估算图片预览
    /// </summary>
    public partial class T_ImgView
    {
        I_ImgView dal = new DataAccess<I_ImgView>().CreateInstance("StorageForecast.D_ImgView");

        public T_ImgView()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(E_ImgView model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(E_ImgView model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {

            return dal.Delete(id);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            return dal.DeleteList(idlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public E_ImgView GetModel(int id)
        {

            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_ImgView> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<E_ImgView> DataTableToList(DataTable dt)
        {
            List<E_ImgView> modelList = new List<E_ImgView>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                E_ImgView model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new E_ImgView();
                    if (dt.Rows[n]["id"].ToString() != "")
                    {
                        model.id = int.Parse(dt.Rows[n]["id"].ToString());
                    }
                    if (dt.Rows[n]["RawID"].ToString() != "")
                    {
                        model.RawID = int.Parse(dt.Rows[n]["RawID"].ToString());
                    }
                    if (dt.Rows[n]["ImgTypeID"].ToString() != "")
                    {
                        model.ImgTypeID = int.Parse(dt.Rows[n]["ImgTypeID"].ToString());
                    }
                    model.Imgname = dt.Rows[n]["Imgname"].ToString();
                    model.ImgPath = dt.Rows[n]["ImgPath"].ToString();
                    if (dt.Rows[n]["UpLoadTime"].ToString() != "")
                    {
                        model.UpLoadTime = DateTime.Parse(dt.Rows[n]["UpLoadTime"].ToString());
                    }
                    if (dt.Rows[n]["UpLoadUserID"].ToString() != "")
                    {
                        model.UpLoadUserID = int.Parse(dt.Rows[n]["UpLoadUserID"].ToString());
                    }
                    model.UpLoadUserName = dt.Rows[n]["UpLoadUserName"].ToString();
                    model.Description = dt.Rows[n]["Description"].ToString();
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        #endregion  Method
    }
}
